import mongoose, { Types } from "mongoose";
import baseModel from "./base-model";
import md5 from "../util/md5";

export enum UserStatus {
  Normal = 0,
  Frozen = 1
}

export const userSchema = new mongoose.Schema({
  ...baseModel,
  name: {
    type: String,
    required: false,
    default: "亲爱的用户"
  },
  username: {
    type: String,
    required: true,
    unique: true
  },
  password: {
    type: String,
    required: true,
    set: (value: string) => md5(value),
    select: false
  },
  email: {
    type: String,
    required: true
  },
  status: {
    type: Number,
    required: false,
    default: UserStatus.Normal
  }
});
